package com.beta.cust.bind.datasync.builder;

import com.alibaba.fastjson.JSONObject;
import com.beta.cust.bind.datasync.constant.BusinessConstant;
import com.beta.cust.bind.datasync.mapper.entity.CustInfo;

import java.sql.Timestamp;
import java.time.LocalDateTime;

/**
 * @Auther: pcc
 * @Date: 2024/3/16 15:42
 * @Description:
 */
public class CustInfoBuilder {
    public static CustInfo buildCustInfo(String externalUserId, JSONObject extUserInfo){
        CustInfo custInfo = new CustInfo();
        // 1表示该外部联系人是微信用户，2表示该外部联系人是企业微信用户
        Integer type = extUserInfo.getInteger("type");
        custInfo.setExternalUserid(externalUserId);
        custInfo.setName(extUserInfo.getString("name"));
        custInfo.setAvatar(extUserInfo.getString("avatar"));
        custInfo.setType(type);
        custInfo.setGender(extUserInfo.getInteger("gender"));
        custInfo.setUnionid(extUserInfo.getString("unionid"));
        if (type == 2) {
            // 仅当联系人类型是企业微信用户时有此字段
            custInfo.setPosition(extUserInfo.getString("position"));
            custInfo.setCorpName(extUserInfo.getString("corp_name"));
            custInfo.setCorpFullName(extUserInfo.getString("corp_full_name"));
        }
        custInfo.setDelFlag(BusinessConstant.IS_NOT_DEL_FLAG);
        custInfo.setCreateTime(Timestamp.valueOf(LocalDateTime.now()));
        custInfo.setUpdateTime(Timestamp.valueOf(LocalDateTime.now()));
            return custInfo;
    }
}
